package com.ycu.epidemic.controller;

import com.ycu.epidemic.bean.*;
import com.ycu.epidemic.service.EpidemicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/epidemicData")
public class EpidemicController {
    @Autowired
    private EpidemicService epidemicService;

    @PostMapping("/ajax/input")
    @ResponseBody
    public AjaxResponseInfo inputData(@RequestBody DailyEpidemicInfo dailyEpidemicInfo, HttpSession session){
        AjaxResponseInfo responseInfo = new AjaxResponseInfo();
        UserInfo user = (UserInfo) session.getAttribute("loginUser");
        if (user == null){
            responseInfo.setCode(-2);
            responseInfo.setMsg("您没有登录");
        }else {
            /**
            *   录入每日疫情数据
             * @Param dailyEpidemicInfo 对前台数据封装
             * @Param session 取到当前用户
            * @Author:lijinhua
            * @Date:2020/7/12
            */
            List<ProvinceInfo>  list = epidemicService.saveData(dailyEpidemicInfo,user.getUserId());
            responseInfo.setData(list);
        }
        return responseInfo;
    }

    @GetMapping("/ajax/lastestData")
    @ResponseBody
    public AjaxResponseInfo findLastestData(){
        /**
        * 查最近的数据（累计）
         * @Param
        * @Author:lijinhua
        * @Date:2020/7/12
        */
        AjaxResponseInfo ajaxResponseInfo = new AjaxResponseInfo();
        List<EpidemicDetailInfo> list = epidemicService.findLastestData();
        ajaxResponseInfo.setData(list);//转成json串
//       System.out.println(ajaxResponseInfo.getData());
        return ajaxResponseInfo;
    }
}
